package leetcode.huadongchuangkou;

public class Test3 {
    public static void main(String[] args) {
        int[] arr = {2, 2, 2, 2, 5, 5, 5, 8};
        System.out.println(numOfSubarrays(arr, 3, 4));
    }

    public static int numOfSubarrays(int[] arr, int k, int threshold) {
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += arr[i];
        }
        int num = 0;
        for (int i = k; i < arr.length; i++) {
            sum += arr[i] - arr[i - k];
            if (sum / k >= threshold) {
                num++;
            }
        }
        return num;
    }
}
